package com.pension.service.impl;


import com.pension.dao.UserDao;
import com.pension.entity.User;
import com.pension.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {


    @Autowired
    private UserDao userDao;

    @Override
    public User login(String username, String password) {
        return userDao.findByUsernameAndPassword(username,password);
    }

    @Override
    public User findUserByIdWithParam(String id) {
        return userDao.findUserByIdWithParam(id);
    }

    @Override
    public void updateUser(User user) {
        userDao.updateUser(user);
    }

    @Override
    public Integer authoritymanagement(String username, String password) {
        return userDao.authoritymanagement(username,password);
    }

    @Override
    public List<User> findAllUser() {
        return userDao.findAllUser();
    }

    @Override
    public void authority(int id) {
        userDao.authority(id);
    }

    @Override
    public void authority2(int id) {
        userDao.authority2(id);
    }

    @Override
    public void deleteByid(int id) {
        userDao.deleteByid(id);
    }

    @Override
    public String aa(String a) {
        return a;
    }

    @Override
    public boolean save(User user) {
        User userDB = userDao.findByUserName(user.getUsername());
        if (userDB==null){
            userDao.save(user);
            return true;
        }else
            return false;
    }


}
